import java.util.ArrayList;
import java.util.Stack;
public class Solution {
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> list=new ArrayList<>();
        if(listNode==null)return list;
        Stack<Integer> stack=new Stack<>();
        ListNode cur=listNode;
        while(cur!=null){
            stack.push(cur.val);
            cur=cur.next;
        }
        while(!stack.isEmpty()){
            list.add(stack.pop());
        }
        return list;
    }
}